<!--
 * @Author: your name
 * @Date: 2021-04-05 21:02:29
 * @LastEditTime: 2021-04-27 18:34:36
 * @LastEditors: Please set LastEditors
 * @Description: 留言板
 * @FilePath: /medicine-web/src/views/messageboard/index.vue
-->
<template>
  <div class="message-board-container">
    <p class="message-title">留言中心</p>
    <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="留言主题:" prop="title">
        <el-input type="text" v-model="ruleForm.title" autocomplete="off" placeholder="请输入留言主题"></el-input>
      </el-form-item>
      <el-form-item label="留言内容:" prop="content">
        <el-input type="textarea" :rows="20" v-model="ruleForm.content" autocomplete="off" placeholder="请输入留言内容"></el-input>
      </el-form-item>
      <el-row :gutter="30">
        <el-col :span="12">
          <el-form-item label="联系人:" prop="linkman">
            <el-input type="text" v-model="ruleForm.linkman" autocomplete="off" placeholder="请输入联系人"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="手机号:" prop="phone">
            <el-input type="text" v-model="ruleForm.phone" autocomplete="off" placeholder="请输入手机号"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="30">
        <el-col :span="12">
          <el-form-item label="邮箱:" prop="email">
            <el-input type="text" v-model="ruleForm.email" autocomplete="off" placeholder="请输入邮箱"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row class="btn-submit">
        <customBtn :btnStr="'确认并发送'" @handClick="submit('ruleForm')"></customBtn>
      </el-row>
    </el-form>
  </div>
</template>
<script>
import customBtn from '@/components/CustomBtn/index.vue'
export default {
  name: 'board',
  components: { customBtn },
  data () {
    const validateTitle = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入留言主题'))
      } else {
        callback()
      }
    }
    const validateContent = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入留言内容'))
      } else {
        callback()
      }
    }
    const checkContact = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入联系人'))
      } else {
        callback()
      }
    }
    const checkPhone = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入手机'))
      } else {
        callback()
      }
    }
    return {
      ruleForm: {
        title: '',
        content: '',
        linkman: '',
        phone: '',
        email: ''
      },
      rules: {
        title: [
          { validator: validateTitle, trigger: 'blur', required: true }
        ],
        content: [
          { validator: validateContent, trigger: 'blur', required: true }
        ],
        linkman: [
          { validator: checkContact, trigger: 'blur', required: true }
        ],
        phone: [
          { validator: checkPhone, trigger: 'blur', required: true }
        ]
      }
    }
  },
  methods: {
    submit(formName) {
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          const res = await this.$action('userFeedback', this.ruleForm)
          if (res) {
            this.$message.success(
              '留言成功！',
              2,
            )
            setTimeout(() => {
              this.$router.push('/main')
            }, 1500)
          }
        } else {
          return false
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
@import '~@/assets/styles/flex.scss';
.message-board-container {
  width: 1100px;
  padding: 58px 0px 121px 0px;
  margin: 0 auto;
  .message-title {
    text-align: center;
    font-size: 1.25rem;
    color: #555555;
    font-weight: bold;
    padding-bottom: 3rem;
  }
  /deep/ .el-form-item__label {
    font-size: 0.875rem;
    color: #555555;
    font-weight: 400;
    text-align: left;
  }
  .btn-submit {
    @include flex-def;
    @include flex-zCenter;
    margin-top: 3.75rem;
    /deep/ .a-btn-container {
      width: 179px;
      height: 54px;
    }
  }
  /deep/ *::-webkit-input-placeholder {
    color: #CCCCCC;
    font-size: 0.875rem;
  }
  /deep/ *:-moz-placeholder {
    /* FF 4-18 */
    color: #CCCCCC;
    font-size: 0.875rem;
  }
  /deep/ *::-moz-placeholder {
    /* FF 19+ */
    color: #CCCCCC;
    font-size: 0.875rem;
  }
  /deep/ *:-ms-input-placeholder {
    /* IE 10+ */
    color: #CCCCCC;
    font-size: 0.875rem;
  }
}
</style>